cmake_minimum_required(VERSION 3.12)

project(qpicturebox LANGUAGES CXX)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)

if (QT_VERSION_MAJOR EQUAL 6)
    find_package(Qt6 COMPONENTS Widgets OpenGLWidgets REQUIRED)
else()
    find_package(Qt5 COMPONENTS Widgets REQUIRED)
endif()

add_library(qpicturebox SHARED
    qpicturebox.cpp
    qpicturebox.h
)

if (QT_VERSION_MAJOR EQUAL 6)
    target_link_libraries(qpicturebox PUBLIC Qt6::Widgets Qt6::OpenGLWidgets)
else()
    target_link_libraries(qpicturebox PUBLIC Qt5::Widgets)
endif()

install(TARGETS qpicturebox
    EXPORT qpictureboxTargets
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION bin
)
install(FILES qpicturebox.h DESTINATION include)

install(EXPORT qpictureboxTargets
    FILE qpictureboxTargets.cmake
    NAMESPACE qpicturebox::
    DESTINATION lib/cmake/qpicturebox
)